package com.geeksonsecurity.malwaredemo.domain;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.google.gson.Gson;

public class Settings {

    private static final String SETTINGS_KEY = "settings";
    private static final Gson _gson = new Gson();

    private boolean _linkedinEnabled = true;
    private boolean _ubsEnabled = true;
    private boolean _skypeEnabled = true;

    private OverlayType _overlayType = OverlayType.VIEW;

    public Settings() {
    }

    public boolean isSkypeEnabled() {
        return _skypeEnabled;
    }

    public void setSkypeEnabled(boolean skypeEnabled) {
        _skypeEnabled = skypeEnabled;
    }

    public boolean isUbsEnabled() {
        return _ubsEnabled;
    }

    public void setUbsEnabled(boolean ubsEnabled) {
        this._ubsEnabled = ubsEnabled;
    }

    public boolean isLinkedinEnabled() {
        return _linkedinEnabled;
    }

    public void setLinkedinEnabled(boolean linkedinEnabled) {
        this._linkedinEnabled = linkedinEnabled;
    }

    public static Settings Load(Context ctx) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
        String json = preferences.getString(SETTINGS_KEY, "");
        if (json.isEmpty()) {
            return new Settings();
        } else {
            return _gson.fromJson(json, Settings.class);
        }
    }

    public static void Save(Context ctx, Settings s) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
        SharedPreferences.Editor edit = preferences.edit();
        String json = _gson.toJson(s);
        edit.putString(SETTINGS_KEY, json);
        edit.commit();
    }

    public OverlayType getOverlayType() {
        return _overlayType;
    }

    public void setOverlayType(OverlayType overlayType) {
        this._overlayType = overlayType;
    }

    @Override
    public String toString() {
        return "Settings{" +
                "_linkedinEnabled=" + _linkedinEnabled +
                ", _ubsEnabled=" + _ubsEnabled +
                ", _skypeEnabled=" + _skypeEnabled +
                ", _overlayType=" + _overlayType +
                '}';
    }

}
